package com.magenta.maxoptra.geocoding.geoinformsputnik;

import java.io.Serializable;
/*
* Project: Santa Cruz
* User: Alex Uraltsev
* Date: 18-Sep-2009 12:44:50
*
* Copyright (c) 1999-2007 Magenta Corporation Ltd. All Rights Reserved.
* Magenta Technology proprietary and confidential.
* Use is subject to license terms.
*/

public class GeoPosition implements Serializable, GeoCoordinates {
    private static final long serialVersionUID = 1;
    private final double latitude;
    private final double longitude;

    /**
     * Creates a new instance of GeoPosition from the specified
     * latitude and longitude. These are double values in decimal degrees, not
     * degrees, minutes, and seconds.  Use the other constructor for those.
     *
     * @param latitude  a latitude value in decmial degrees
     * @param longitude a longitude value in decimal degrees
     */
    public GeoPosition(double latitude, double longitude) {
        this.latitude = latitude;
        this.longitude = longitude;
    }

    // must be an array of length two containing lat then long in that order.


    public GeoPosition(GeoCoordinates trackingInfo) {
        this(trackingInfo.getLatitude(), trackingInfo.getLongitude());
    }

    /**
     * Get the latitude as decimal degrees
     *
     * @return the latitude as decimal degrees
     */
    public Double getLatitude() {
        return latitude;
    }

    /**
     * Get the longitude as decimal degrees
     *
     * @return the longitude as decimal degrees
     */
    public Double getLongitude() {
        return longitude;
    }

    /**
     * Returns true the specified GeoPosition and this GeoPosition represent
     * the exact same latitude and longitude coordinates.
     *
     * @param obj a GeoPosition to compare this GeoPosition to
     * @return returns true if the specified GeoPosition is equal to this one
     */
    public boolean equals(Object obj) {
        if (obj instanceof GeoPosition) {
            GeoPosition coord = (GeoPosition) obj;
            return coord.latitude == latitude && coord.longitude == longitude;
        }
        return false;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        temp = latitude != +0.0d ? Double.doubleToLongBits(latitude) : 0L;
        result = (int) (temp ^ (temp >>> 32));
        temp = longitude != +0.0d ? Double.doubleToLongBits(longitude) : 0L;
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }

    /**
     * {@inheritDoc}
     *
     * @return
     */
    public String toString() {
        return "[" + latitude + ", " + longitude + "]";
    }
}
